# this code creates a matrix with numbers simulating Voronoi diagram
# it is NOT an implementation of any normal algorithm - at least it;s not what I intended


# let's choose randomly some 2-dimensional feature points
import random

size = 1000
featurePointsNumber = 150

n1 = [(random.randint(0, size-1)) for j in range(featurePointsNumber)]
n2 = [(random.randint(0, size-1)) for j in range(featurePointsNumber)]

# now we have 2 sets of randomly choosen numbers between 0 and 'size' (exclusive)
# we'll use them as x and y coordinates for feature points
# now we need to create a square matrix of some size

matrix = [[-1 for i in range(size)] for j in range(size)]

# definition of a 'metric'
# one point has coordinates (x1, x2), while the other one has (y1, y2)
def dist(x1, x2, y1, y2):

    dx = x1 - y1
    dy = x2 - y2
    
    return (dx * dx) + (dy * dy)


# finding shortest distance to some feature point
def distFromFeaturePoints(x1, x2):

    secondShortest = size * size
    shortest = size * size
    distance = 0
    
    for i in range(featurePointsNumber):
        
        distance = dist(x1, x2, n1[i], n2[i])
    
        if distance <= shortest:
            secondShortest = int(shortest)
            shortest = int(distance)

        elif (distance <= secondShortest) and (distance > 0):
            secondShortest = int(distance)

    return (shortest, secondShortest)

# now, assuming that coefficients C1 and C2 are equal -1 and 1, let's calculate distances
C1 = -1
C2 = 1

# now we need to determine the shortest possible distance between the given point and some feature point

for i in range(size):
    for j in range(size):

        distances = distFromFeaturePoints(i, j)
        matrix[i][j] = C1 * distances[0] + C2 * distances[1]
        

#for row in matrix:
#    print row

# optional - writing to the file
#file = open('results.txt', 'w')
#for row in matrix:
#    for element in row:
#        file.write(str(element))
#        file.write(str('; '))
#    file.write(str("\n"))
#file.close()

# optional - representation via matplotlib
#import matplotlib.pyplot as plt
#
#plt.imshow(matrix)
#plt.show()

